$(document).ready(function(){
	var $container = $("#container");
	$container.append()
	
	
	$("#person_new").click(function(){
		_initializeNewPersonWindow();
		$("#person_new_window").dialog("open");
	});
});

function _initializeNewPersonWindow(){
	var $window = $("#person_new_window");
	
	$window.append( _windowRow("Apellidos", "lastNames") );
	$window.append( _windowRow("Nombres", "firstNames") );
	$window.append( _windowRow("DNI", "document") );
	$window.append( _windowRow("Direcci&oacute;n", "address") );
	$window.append( _windowRow("Localidad", "city") );
	$window.append( _windowRow("Provincia", "state") );
	$window.append( _windowRow("C&oacute;digo Postal", "zipCode") );
	$window.append( _windowRow("Nacionalidad", "country") );
	$window.append( _windowRow("Fecha de Nacimiento", "d_birth") );
	$window.append( _windowRow("Estado Civil", "maritalStatus") );
	$window.append( _windowRow("Tel&eacute;fono", "phone") );
	$window.append( _windowRow("Celular", "cellphone") );
	$window.append( _windowRow("Estudios Cursados", "studies") );
	$window.append( _windowRow("Profesi&oacute;n", "profession") );
	$window.append( _windowRow("N&uacute;mero de Socio", "associateNumber") );
	$window.append( _windowRow("Fecha de Ingreso a la Instituci&oacute;n", "d_in") );
	$window.append( _windowRow("Adscripto a la Escuela", "assigned") );
	$window.append( _windowRow("Fecha de Compromiso", "d_compromise") );
	
	$window.find('input').filter(function(){
		return this.id.match("^d_");
	}).datepicker();
	
	var toSend = null;
	$window.dialog({
		width: 300,
		height: 450,
		modal: true,
		buttons: {
			"Aceptar" : function(){
				$.ajax({
					"dataType" : "json",
					"contentType" : "application/json",
					"data" : JSON.stringify(toSend),
					"type" : "POST",
					"url" : "save",
					"cache" : false,
					"success" : function(data){
						
					}
				});
			},
			"Cancelar" : function(){
				$(this).dialog("close");
			}
		}
	});
	
	function _windowRow(spanContent, inputId){
		return $( 
			'<span class="show-grid">' +
				'<span class="span3">' + spanContent + ':</span>' +
				'<input class="span3" id="' + inputId + '" />' + 
			'</span>'
		);
	}
}